#! /usr/bin/perl -w

use strict;
$| = 1;

my ($ip, $mac);

## root privilege need to get mac while using nmap
if ( $> != 0 ) {
    die "root privilege need to get mac while using nmap";
}

open( PIPE, "nmap 192.168.1.0/24 -n -sP |" )
    or die "Can not open pipe for nmap";

while (<PIPE>) {
    if ( /^Host\s+(192\.168\.1\.\d+)\s+appears to be up/ ) {
        $ip = $1;
    }
    elsif ( /^MAC Address: ((?:\w\w:){5}\w\w)/) {
        $mac = $1;
        print "$ip $mac\n"
    }
}
__DATA__
Host 192.168.1.1 appears to be up.
MAC Address: 00:0E:A0:00:4C:2D (NetKlass Technology)

